<?php
/**
 * Description of ExaminModule
 * 审核策略Module
 * @author
 */
//require_rewrite(MODULE_ROOT.'dao/UserDao.class.php');
class ExaminModule extends BaseModule{

    public function __construct() {
        parent::__construct();
    }

    /**
     * 查找策略
     * @param str $name 策略名称
     */
    public function selList($name='',$id=''){
        $db = DB_MySQLi::getInstance();
        if (!empty($name)) {
            $sql = "select * from check_str_rule where name='".$name."'" ;
        } elseif(!empty($id)) {
            $sql = "select * from check_str_rule where id='".$id."'" ;
        }else{
            $sql = "select * from check_str_rule order by id";
        }
        $query = $db->getData_ASSOCS($sql);
        return $query;
    }
    /**
     * 添加编辑审批策略
     * @param str $name 审批策略名称
     * @param int $type 策略类型
     * @param str $str 密级设置
     * @param int $id 编辑策略ID
     */
    public function sqlList($name,$type,$str,$id=''){
        $db = DB_MySQLi::getInstance();
        if(!empty($id)){
            $sql="UPDATE check_str_rule SET name ='".$name."',type ='".$type."',level ='".$str."' where id='".$id."'";
        }else{
            $sql="insert into check_str_rule(name,type,level) values ('" .$name. "','" .$type. "','".$str."')";
        }
        $query = $db->query($sql);
        return $query;
    }

    /**
     * 删除审批策略
     */
    public function SqlDel($id){
        $db = DB_MySQLi::getInstance();
        $sql="delete from check_str_rule where id='".intval($id)."'";
        $query = $db->query($sql);
        return $query;
    }

    /**
     * 删除审批流程
     */
    public function SqlBatchDel($id){
        $db = DB_MySQLi::getInstance();
        $sql="delete from check_rule where id='".intval($id)."'";
        $query = $db->query($sql);
        return $query;
    }

    /**
     * 查找审批流程
     */
    public function SqlBatch($name='',$id=''){
        $db = DB_MySQLi::getInstance();
        if (!empty($name)) {
            $sql = "select * from check_rule where name='".$name."'" ;
        } elseif(!empty($id)) {
            $sql = "select * from check_rule where id='".$id."'" ;
        }else{
            $sql = "select * from check_rule order by id";
        }
        $query = $db->getData_ASSOCS($sql);
        foreach($query as $key=>$row){
            $groud=UserDao::getDepartmentList($row['group_id']);
            $query[$key]['groud_name']=$groud[0]['nickname'];
            $query[$key]['levelname']=$this->getLevelName($row['level_id']);
        }
        return $query;
    }

    public function getLevelName($id){
        switch($id){
            case 0:
                    return '绝密';
                    break;
            case 1:
                    return '机密';
                    break;
            case 2:
                    return '秘密';
                    break;
            case 3:
                    return '内部';
                    break;
            case 4:
                    return '非密';
                    break;
        }
    }
    /**
     * 添加审批流程
     */
    public function addSqlBatch($array){
        $db = DB_MySQLi::getInstance();
        $sql="insert into check_rule(name,group_id,type,level_id,check_user_ids)
            values ('" .$array['process_name']. "','" .$array['groudid']. "','".$array['rule_type']."','".$array['levelId']."','".$array['level_userid']."')";
        $query = $db->query($sql);
        return $query;
    }

    /**
     * 编辑审批流程
     */
    public function upSqlBatch($array,$id){
        $db = DB_MySQLi::getInstance();
        if(!empty($id)){
            $sql="UPDATE check_rule SET name ='".$array['process_name']."',group_id ='".$array['groudid']."',type ='".$array['rule_type']."',level_id='".$array['levelId']."',check_user_ids='".$array['level_userid']."' where id='".$id."'";
        }
        $query = $db->query($sql);
        return $query;
    }
}
?>